package com.danco.planner.viewcontrollers;

import com.danco.planner.services.LecturesListService;
import com.danco.planner.supportclasses.enumeration.IEventType;
import com.danco.planner.supportclasses.enumeration.PlannerEventType;
import com.danco.planner.view.builders.AbstractViewsBuilder;
import com.danco.planner.view.builders.ConsoleViewsBuilder;
import com.danco.planner.view.core.AbstractButton;
import com.danco.planner.view.core.View;

public class LecturesVC extends AbstractPlannerVC {

	public LecturesVC() {
		super();
	}
	public LecturesVC(View view) {
		super(view);
	}
	public LecturesVC(View view, String title) {
		super(view, title);
	}
	
	@Override
	protected void initAllOtherSubviews() {
		
		AbstractViewsBuilder builder = new ConsoleViewsBuilder();
		
		AbstractButton sortByNameBtn = builder.buildButton("Sort by name", "sbName", PlannerEventType.sortByName);
		AbstractButton sortByDate = builder.buildButton("Sort by date", "sbDate", PlannerEventType.sortByDate);
		
		sortByNameBtn.addListener(this);
		sortByDate.addListener(this);
		
		baseView.addSubviews(sortByNameBtn,sortByDate);	
	}
	@Override
	protected String getMainContent() {
		return "";
	}
	
	@Override
	public void handleAction(Object arg0, IEventType arg1) {
		
		super.handleAction(arg0, arg1);
		
		if (arg1 == PlannerEventType.sortByName) {
			sortByName();
		}
		else if (arg1 == PlannerEventType.sortByDate) {
			sortByDate();
		}
	}
	
	private void sortByName() {
		this.contentLabel.setText(LecturesListService.getLecturesListDescriptionSortedByName());
	}
	private void sortByDate() {
		this.contentLabel.setText(LecturesListService.getLecturesListDescriptionSortedByDate());
	}
}
